<?php

namespace App\Http\Controllers\Labaicai;

use App\Models\Me;
use App\Models\MeArticle;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class MeController extends Controller
{
    /**
     * Store a newly created resource in storage.
     *
     * @param \Illuminate\Http\Request $request
     */
    public function index(Request $request)
    {
        Me::query()->create($request->all());
    }

    public function show($id)
    {
        $result = Me::query()->where('id', $id)->first();
        $result->articles()->createMany([
            ['title' => 'test title'],
            ['title' => 'test title2'],
        ]);
        return $result->toArray();
    }


    public function get($id)
    {
        $result = Me::query()->where('id', $id)->first();
        return $result->toArray();
    }

    public function articles($id)
    {
        $result = MeArticle::all()->groupBy(function ($item) {
            return $item->title[-1];
        });
        return $result->toArray();
    }
}
